package com.jiaai.cloud.system.controller;


import com.jiaai.cloud.base.exception.ServiceException;
import com.jiaai.cloud.base.util.RestResultGenerator;
import com.jiaai.cloud.system.entity.TRobot;
import com.jiaai.cloud.system.service.ITRobotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2017-08-26
 */
@RestController
@RequestMapping("/api/manage/tRobot")
public class TRobotController {
    @Autowired
    private ITRobotService itRobotService;


    //查所有
    @RequestMapping(value ="/findByAll",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object findByAll( ) throws ServiceException {
        try {
            return RestResultGenerator.genSuccessResult(itRobotService.selectList(null));
        } catch (Exception e) {
            throw new ServiceException("查询失败", e.getMessage());
        }
    }
    //    删除
    @RequestMapping(value = "/deleteId/{id}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public Object deleteId(@PathVariable("id") Integer id) throws ServiceException {
        try {
            itRobotService.deleteById(id);
            return RestResultGenerator.genSuccessResult();
        } catch (Exception e) {
            throw new ServiceException("删除失敗", e.getMessage());
        }
    }

    //通过改anchorId改status状态
    @RequestMapping(value = "/changeStatus/{id}/{status}", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object changeStatus(@PathVariable("id") Integer id, @PathVariable("status") Integer status) throws ServiceException {
        try {
            TRobot tRobot = new TRobot();
            tRobot.setId(id);
            tRobot.setStatus(status);
            itRobotService.updateById(tRobot);
            return RestResultGenerator.genSuccessResult();
        }catch (Exception e) {
            throw new ServiceException("修改失敗", e.getMessage());
        }
    }

}
